<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="box">
			<button data-id="1">1</button>
			<button data-id="2">2</button>
			
			<button data-id="+">+</button>
			<button data-id="-">-</button>
			<button data-id="*">*</button>
			<button data-id="/">/</button>
			
			<button data-id="=">=</button>
		</div>
		<script>
			let box=document.getElementById("box");
			let str="";
			box.onclick=function(e){
				if(e.target.tagName=="BUTTON"){
					//console.log(e.target.getAttribute("data-id"));
					let type=e.target.getAttribute("data-id");
					if(type=="="){//计算结果
						console.log(eval(str));
						str="";
						return;
					}
					str+=type;
					console.log(str);
				}
			}
		</script>
	</body>
</html>
